package stark.app.function.pctrl;

import com.stark.parentctrl.lib.ParentCtrl;

import stark.app.R;
import stark.app.databinding.ActivityPctrlDemoBinding;
import stark.common.basic.base.BaseNoModelActivity;

/**
 * Author：daizhongbin on 2023/2/15
 * Email：1027154338@qq.com
 * Desc:
 */
public class ParentCtrlDemoActivity extends BaseNoModelActivity<ActivityPctrlDemoBinding> {

    @Override
    protected int onCreate() {
        return R.layout.activity_pctrl_demo;
    }

    @Override
    protected void initView() {
        mDataBinding.btnPctrl.setOnClickListener(v -> {
            clickBtnPctrl();
        });
        //启动应用，进入主界面时要调用该方法，比如在HomeActivity中调用。这里调用只是做示范用
        ParentCtrl.checkToShowPwdOnEnterHome(this);
    }

    @Override
    protected void initData() {
    }

    @Override
    protected void onResume() {
        super.onResume();
        updateBtnPctrl();
    }

    private void updateBtnPctrl() {
        String text;
        if (ParentCtrl.isOpen()) {
            text = "家长控制已开启，点击关闭";
        } else {
            text = "家长控制已关闭，点击开启";
        }
        mDataBinding.btnPctrl.setText(text);
    }

    private void clickBtnPctrl() {
        if (ParentCtrl.isOpen()) {
            ParentCtrl.reqCloseCtrl(this);
        } else {
            ParentCtrl.reqOpenCtrl(this);
            updateBtnPctrl();
        }
    }
}
